package com.yylending.remotevideo;

import com.yyfax.common.CLog;
import com.yyfax.infrastructure.eventbus.EventAgent;
import com.yyfax.infrastructure.mvp.IView;
import com.yyfax.infrastructure.mvp.Presenter;
import com.yyfax.infrastructure.mvp.PresenterFactory;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

/**
 * Created by HenryZhang on 2017/4/12.<br>
 * Copyright © 2017 www.yylending.com. All Rights Reserved.<br><br>
 */
public class VideoPresenter extends Presenter<VideoModel, VideoPresenter.View> {

	public static class Generator implements PresenterFactory<VideoPresenter> {
		@Override
		public VideoPresenter create() {
			return new VideoPresenter();
		}
	}

	public interface View extends IView {
		void signResult(VideoModel.SignResult result);
	}

	private View mView;

	@Override
	public void attach(View view) {
		mView = view;
		mModel = new VideoModel();
		EventAgent.register(this);
	}

	@Override
	public void detach() {
		mView = null;
		mModel = null;
		EventAgent.unregister(this);
	}

	public void sign(String number) {
		execute(number, FUNCTIONAL_CODE, false);
	}

	@Subscribe(threadMode = ThreadMode.MAIN)
	public void signResult(VideoModel.SignResult result) {
		CLog.i("SignPresenter", "SignResult = " + result);
		mView.signResult(result);
	}
}
